<script setup>
import { ref, onMounted } from 'vue'
// 引入 echarts 核心模块，核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core';
// 引入柱状图图表，图表后缀都为 Chart
import { PieChart } from 'echarts/charts';
// 引入提示框，标题，直角坐标系，数据集，内置数据转换器组件，组件后缀都为 Component
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent
} from 'echarts/components';
// 标签自动布局、全局过渡动画等特性
import { LabelLayout, UniversalTransition } from 'echarts/features';
// 引入 Canvas 渲染器，注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers';

// 注册必须的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  PieChart,
  LabelLayout,
  UniversalTransition,
  CanvasRenderer
]);
const pieChartIntroduce=ref(null)
const introduceInstance=ref(null)
const pieChartEvents=ref(null)
const eventsInstance=ref(null)
onMounted(()=>{
  introduceInstance.value=echarts.init(pieChartIntroduce.value)
  introduceInstance.value.setOption({
    title: {
    text: 'Referer of a Website',
    subtext: 'Fake Data',
    left: 'center'
  },
  tooltip: {
    trigger: 'item'
  },
  legend: {
    orient: 'vertical',
    left: 'left'
  },
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: '50%',
      data: [
        { value: 1048, name: 'Search Engine' },
        { value: 735, name: 'Direct' },
        { value: 580, name: 'Email' },
        { value: 484, name: 'Union Ads' },
        { value: 300, name: 'Video Ads' }
      ],
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }
  ]
  })
  //
  eventsInstance.value=echarts.init(pieChartEvents.value)
  eventsInstance.value.setOption({
    tooltip: {
    trigger: 'item'
  },
  legend: {
    top: '5%',
    left: 'center'
  },
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: ['40%', '70%'],
      avoidLabelOverlap: false,
      label: {
        show: false,
        position: 'center'
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 40,
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      },
      data: [
        { value: 1048, name: 'Search Engine' },
        { value: 735, name: 'Direct' },
        { value: 580, name: 'Email' },
        { value: 484, name: 'Union Ads' },
        { value: 300, name: 'Video Ads' }
      ]
    }
  ]
  })
})
const dateValue = ref(null)
console.log(dateValue.value)
//分页
const form = ref({
  pageNum: '1',
  pageSize: '10'
})
const pageChange = (newPage) => {
  form.value.pageNum = newPage
}
const total = ref(200)
</script>
<template>
  <div class="container">
    <div class="header">
      <div class="firstbox tabBox">
        <div style="width: 100%">
          <el-date-picker
            v-model="dateValue"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="large"
            :default-value="[new Date(2023, 3, 1), new Date(2023, 6, 19)]"
          />
        </div>
      </div>
      <div class="chartBox">
        <div style="width: 500px;height: 500px;" ref="pieChartIntroduce"></div>
        <div style="width: 500px;height: 500px;" ref="pieChartEvents"></div>
      </div>
      <!-- // -->
      <h3 class="titleBox">渠道统计报表</h3>
      <!-- /// -->
      <div class="searchBox">
        <el-form :inline="true" label-position="top">
          <el-form-item label="活动编号">
            <el-input placeholder="请输入活动编号" size="large" style="width: 280px"></el-input>
          </el-form-item>
          <el-form-item label="活动名称">
            <el-input placeholder="请输入活动名称" size="large" style="width: 280px"></el-input>
          </el-form-item>
        </el-form>
        <div style="margin-top: 30px">
          <el-button type="success" round size="large" style="width: 94px">搜索</el-button>
          <el-button type="info" round size="large" style="width: 94px">重置</el-button>
        </div>
      </div>
      <!-- //// -->
      <div class="tableBox">
        <el-table :data="tableData" style="width: 100%" stripe>
          <el-table-column label="渠道来源" />
          <el-table-column label="活动编号" />
          <el-table-column label="活动名称" />
          <el-table-column label="活动简介" />
          <el-table-column label="线索总数" />
          <el-table-column label="伪线索数" />
          <el-table-column label="转化商机数" />
          <el-table-column label="转化客户数" />
          <el-table-column label="成交金额" />
          <el-table-column label="活动成本" />
          <el-table-column label="创建时间" sortable></el-table-column>
        </el-table>
        <el-row type="flex" justify="center">
          <el-pagination
            v-model:current-page="form.pageNum"
            v-model:page-size="form.pageSize"
            :page-sizes="[10, 20, 30, 50]"
            :small="small"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @current-change="pageChange"
            @size-change="pageSizeChange"
          />
        </el-row>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.container {
  background-color: #fff;
  .tabBox {
    display: flex;
    justify-content: space-between;
    padding: 14px 20px;
    .imgBox {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
    }
  }
  .chartBox{
    display: flex;
    justify-content: space-between;
  }
  .titleBox {
    height: 83px;
    line-height: 83px;
    padding-left: 21px;
    background-color: #f9f9f9;
  }
  .searchBox {
    display: flex;
    justify-content: space-between;
    padding: 10px 56px 40px 45px;
  }
  :deep(.el-input__wrapper) {
    border-radius: 10px;
    background-color: #f9f9f9;
  }
}
</style>
